import { ViewUtil } from "db://app-game/core/utils/ViewUtil";
import { GameResPath } from "../../config/GameResPath";
import { DBMapType } from "./DBMap.type";
import { JsonUtil } from "db://app-game/core/utils/JsonUtil";

export class DBMap {
  /** 表单名称 */
  static DBName = "Map";
  /** 表单数据 */
  data: DBMapType = null!;
  init(id: number) {
    let db = JsonUtil.get(DBMap.DBName) as DBMapType[];
    this.data = db.find((v) => v.id === id)!;
  }

  /** 获取地图资源 */
  createMapNode(mapFilePath: string, initPos: { row: number; col: number }) {
    const mapName = this.data.mapTable[initPos.row][initPos.col];
    const mapPath = GameResPath.getLevelMapPath(mapFilePath, mapName);
    const node = ViewUtil.createTiledMapNode(mapPath);
    return node;
  }
}
